<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>添加商品信息</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/Public/admin/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/Public/admin/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="/Public/admin/assets/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/Public/admin/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/Public/admin/assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="/Public/admin/assets/css/app.css">
    <script src="/Public/admin/assets/js/jquery.min.js"></script>
 <!-- 引用控制层插件样式 -->
    <link rel="stylesheet" href="/Public/tools/php_img_upload/control/css/zyUpload.css" type="text/css">
</head>

<body data-type="widgets">
    <script src="/Public/admin/assets/js/theme.js"></script>
    <div class="am-g tpl-g">
       <include file="./Application/Admin/View/Share/header.html"/>
        <include file="./Application/Admin/View/Share/left.html"/>

        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">

            <div class="container-fluid am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
                        <eq name="goodstag" value="">
                        <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 商品管理 <small>新增商品</small></div>
                        <p class="page-header-description">你可以添加新的商品信息并保存</p>
                        <else/>
                        <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span> 商品管理 <small>编辑商品</small></div>
                        <p class="page-header-description">你可以编辑商品信息并保存</p>
                        </eq>
                        
                    </div>
                    <div class="am-u-lg-3 tpl-index-settings-button">
                        
                    </div>
                </div>

            </div>

            <div class="row-content am-cf">


                <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">商品信息表 </div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr">

                                <form class="am-form tpl-form-line-form" method="post" enctype="multipart/form-data" action="/Admin/Goods/savegoods?goods_id={$Goodsdata.id}">



                                  <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品一级分类 <span class="tpl-form-line-small-title">SortName</span></label>
                                        <div class="am-u-sm-9">
                                                    <select data-am-selected="{searchBox: 1}" style="display: none;" name="sortid" id="selonesort">
                                                                <eq name="goodstag" value="">
                                                                    <option value="0">一级分类</option>            
                                                                    <volist name="sortlist" id="vo" empty="暂时没有数据">
                                                                    <option value="{$vo.id}">{$vo.sortname}</option>            
                                                                    </volist>
                                                                    <else/>
                                                                        <option value="{$Goodsdata.sortid}">{$Goodsdata.sortname}</option>
                                                                        <volist name="sortlist" id="vo" empty="暂时没有数据">
                                                                            <eq name="vo.id" value="$Goodsdata.sortid">
                                                                            <else/>
                                                                             <option value="{$vo.id}">{$vo.sortname}</option>    
                                                                            </eq>    
                                                                        </volist>
                                                                </eq>
                                                                
                                                    </select>
                                                    <small>请选择一级分类名称。</small>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-phone" class="am-u-sm-3 am-form-label">商品二级分类 <span class="tpl-form-line-small-title">TwoSortName</span></label>
                                        <div class="am-u-sm-9">
                                                    <select data-am-selected="{searchBox: 1}" style="display: none;" name="twosortid"  id="seltwosort">
                                                                <eq name="goodstag" value="">
                                                                <option value="0">二级分类</option> 
                                                                <else/>
                                                                <option value="{$Goodsdata.twosortid}">{$Goodsdata.twosortname}</option>
                                                                <volist name="Goodsdata.twosortlist" id="vo">
                                                                            <eq name="vo.twosortname" value="$Goodsdata.twosortname">
                                                                            <else/>
                                                                            <option value="{$vo.id}">{$vo.twosortname}</option>    
                                                                            </eq>
                                                                </volist>
                                                                </eq>
                                                                

                                                    </select>
                                                    <small>请选择二级分类名称。</small>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品名称 <span class="tpl-form-line-small-title">GoodsName</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" name="goodsname" placeholder="请输入商品名称" value="{$Goodsdata.goodsname}">
                                            <small>请填写商品名称。</small>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品原价 <span class="tpl-form-line-small-title">GoodsOrig</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" name="goodsorig" placeholder="请输入商品原价" value="{$Goodsdata.goodsorig}">
                                            <small>请填写商品原价。</small>
                                        </div>
                                    </div>

                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品现价 <span class="tpl-form-line-small-title">GoodsNow</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" name="goodsnow" placeholder="请输入商品现价" value="{$Goodsdata.goodsnow}">
                                            <small>请填写商品现价。</small>
                                        </div>
                                    </div>

                                     <div class="am-form-group">
                                        <label for="user-weibo" class="am-u-sm-3 am-form-label">商品展示图片 <span class="tpl-form-line-small-title">GoodsImages</span></label>
                                        <div class="am-u-sm-9">
                                            <div class="am-form-group ">
                                                <div class="tpl-form-file-img">
                                                     <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3 am-avg-md-3 am-avg-lg-4 am-gallery-default" data-am-gallery="{ pureview: true }" id="imgshowlist">
                                                    <eq name="Goodsdata" value="">
                                                    <else/>
                                                    <volist name="Goodsdata.goodsimg" id="v">
                                                     <li style="position:relative; width:600px;height:600px;margin-bottom:20px;" >
                                                       <div class="am-gallery-item">
                                                           <a href="" class="">
                                                             <img src="{$v}"  alt="" style="width:600px; height:600px; background:#fff"/>
                                                             <input type="hidden" name="imgs[]" value="{$v}" />
                                                             <a class="am-close am-close-alt" onclick="delimg(this)" style="position:absolute; top:1px;left:590px; ">&times;</a>
                                                            </a>
                                                        </div>
                                                    </li>
                                                    </volist>
                                                    </eq>
                                
                                                 </ul>
                                                </div>
                                                <button type="button" class="am-btn am-btn-danger am-btn-sm" data-am-modal="{target: '#upload-modal', closeViaDimmer: 0, width: 700, height: 360}">
    <i class="am-icon-cloud-upload" ></i> 添加展示图片</button>
                                            </div>

                                        </div>
                                    </div>


                                    <div class="am-form-group">
                                        <label for="user-email" class="am-u-sm-3 am-form-label">商品详情 <span class="tpl-form-line-small-title">Goodsdetail</span></label>
                                        <div class="am-u-sm-9">
                                        <script id="container" name="goodsdetail" type="text/plain">
                                        {$Goodsdata.goodsdetail}
                                        </script>
                                            <small>商品详情为必填</small>
                                        </div>
                                    </div>                  

                                    <div class="am-form-group">
                                        <label for="user-email" class="am-u-sm-3 am-form-label">发布时间 <span class="tpl-form-line-small-title">Createdate</span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="am-form-field tpl-form-no-bg" placeholder="发布时间" data-am-datepicker="" readonly="" name="createdate" value="{$Goodsdata.createdate}">
                                            <small>发布时间为必填</small>
                                        </div>
                                    </div>

                                                

                                    <div class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

        
         

            </div>
        </div>
    </div>
    </div>

      <!-- 模态窗口用于上传图片 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="upload-modal">
            <div class="am-modal-dialog">
                          <div class="am-modal-hd">图片上传
                                    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                          </div>
                          <div class="am-modal-bd">
                                    <div id="demo" class="demo" ></div>
                                    <div id="successinfo"></div>
                          </div>
            </div>
</div>
<!-- 模态窗口end -->
    <script src="/Public/admin/assets/js/amazeui.min.js"></script>
    <script src="/Public/admin/assets/js/amazeui.datatables.min.js"></script>
    <script src="/Public/admin/assets/js/dataTables.responsive.min.js"></script>
    <script src="/Public/admin/assets/js/app.js"></script>
<!-- 图片上传 -->
    <!-- 引用核心层插件 -->
<script type="text/javascript" src="/Public/tools/php_img_upload/core/zyFile.js"></script>
<!-- 引用控制层插件 -->
<script type="text/javascript" src="/Public/tools/php_img_upload/control/js/zyUpload.js"></script>
<script type="text/javascript" src="/Public/tools/UEditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/Public/tools/UEditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container');
function do_submit(){
    document.article_form.submit();
}
</script>
<script type="text/javascript" >
    
    $(function(){
    // 初始化插件
    var width = $(window).width();
    if ( width >= 650 )  width = '100%';
    else    width = "100%";

    $("#demo").zyUpload({
        width            :   width,                 // 宽度
        height           :   "auto",                 // 宽度
        itemWidth        :   "140px",                 // 文件项的宽度
        itemHeight       :   "100px",                 // 文件项的高度
        //url              :   "/upload/UploadAction",  // 上传文件的路径
        url              :   "/Admin/Upload/upGoodsImg",
        inputName        :  '_img[]',
        id               :   1,
        multiple         :   true,                    // 是否可以多个文件上传
        dragDrop         :   false,                    // 是否可以拖动上传文件
        del              :   true,                    // 是否可以删除文件
        finishDel        :   false,                   // 是否在上传文件完成后删除预览
        /* 外部获得的回调接口 */
        onSelect: function(selectFiles, allFiles){    // 选择文件的回调方法  selectFile:当前选中的文件  allFiles:还没上传的全部文件
            console.info("当前选择了以下文件：");
            console.info(selectFiles);
        },
        onProgress: function(file, loaded, total){    // 正在上传的进度的回调方法
            var eleProgress = $("#uploadProgress_" + file.index), percent = (loaded / total * 100).toFixed(2) + '%';
            eleProgress.html(percent);
            console.info(file.index);
            console.info("当前正在上传此文件：");
            console.info(file.name);
            console.info("进度等信息如下：");
            console.info(loaded);
            console.info(total);
        },   
        onDelete: function(file, files){              // 删除一个文件的回调方法 file:当前删除的文件  files:删除之后的文件
            console.info("当前删除了此文件：");
            console.info(file.name);
        },
        onSuccess: function(file, response){          // 文件上传成功的回调方法
            console.info("此文件上传成功：");
            $('#successinfo').append("<p>"+response+"</p>");
            console.info(response);
            var html= '<li style="position:relative;width:600px;height:600px;margin-bottom:20px">'
                           +'<div class="am-gallery-item">'
                               +'<a href="" class="">'
                                 +'<img src="'+response+'"  alt="" style="width:600px; height:600px; background:#fff"/>'
                                 +'<input type="hidden" name="imgs[]" value="'+response+'" />'
                                 +'<a class="am-close am-close-alt" onclick="delimg(this)" style="position:absolute; top:1px;left:590px; ">&times;</a>'
                                +'</a>'
                            +'</div>'
                          +'</li>';
            $('#imgshowlist').append(html);
            $('#upload-modal').modal('close');
            // alert(response);

        },
        onFailure: function(file, response){          // 文件上传失败的回调方法
            $("#uploadImage_" + file.index).css("opacity", 0.2);
            console.info("此文件上传失败：");
            console.info(file.name);
        },
        onComplete: function(response){               // 上传完成的回调方法
            console.info("文件上传完成");
            console.info(response);
        }
    });
    
});

</script>

<script>
            function delimg(obj){
                          $(obj).parents('li').remove();
            }
            //改变显示的二级分类列表
            $("#selonesort").change(function(){
                         var a=$(this).val();
                         if (a!=0) {
                                       $.ajax({
                                                    type: "POST",
                                                    url: "{:u('/API/Goods/loadtwosort')}",
                                                    data: {"sortid":a},
                                                    dataType: "json",
                                                    success: function (res) {   
                                                                 $("#seltwosort").html("<option value=''>请选择二级分类</option>");
                                                                 $.each(res.data, function(i, item) {
                                                                             $("#seltwosort").append("<option value='" + item.id + "'>" + item.twosortname + "</option>");
                                                                  });
                                                    },  
                                                    eror: function (res) {   
                                                                 alert("请求超时!")    
                                                    }       
                                       });
                         }
            });

            
</script>

</body>

</html>